package com.augurit.gzcgwsp.state.web;

import java.io.IOException;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts2.ServletActionContext;
import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Namespace;
import org.apache.struts2.convention.annotation.ParentPackage;
import org.apache.struts2.convention.annotation.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;
import org.springside.modules.orm.Page;
import org.springside.modules.web.struts2.Struts2Utils;

import com.augurit.common.system.web.auth.form.LoginUserForm;
import com.augurit.common.system.web.org.form.OmOrgForm;
import com.augurit.common.util.ExtUtils;
import com.augurit.common.util.lang.DateUtils;
import com.augurit.common.util.lang.StringUtils;
import com.augurit.gzcgwsp.state.service.IYwXzXkSpStateService;
import com.augurit.gzcgwsp.state.util.RequestUtil;
import com.augurit.gzcgwsp.state.web.form.YwRqStateForm;
import com.opensymphony.xwork2.ActionSupport;
import com.opensymphony.xwork2.ModelDriven;
@Component("ywXzxkspStateAtcion")
@ParentPackage("struts-default")
@Namespace("/state")
@Scope("prototype")
@Action(value="ywxzxksp-state",results={
	 	@Result(name = "success", location = "/gzcgwsp/state/listXzxkState.jsp"),
	 	@Result(name = "resultState", location = "/gzcgwsp/state/rqstate/listResultState.jsp"),
	 	@Result(name = "resultInfo", location = "/gzcgwsp/state/rqstate/listStateData.jsp")
	}
)
/**
 * 燃气处行政许可审批查询Action
 */
public class YwXzxkspStateAtcion extends ActionSupport implements ModelDriven {
	@Autowired
	private IYwXzXkSpStateService ywXzXkSpStateService;
	private Page page ;

	public Page getPage() {
		return page;
	}
	public void setPage(Page page) {
		this.page = page;
	}
	
	
	/**
	 * 分页统计查询
	 * @return
	 */
    public String toList(){
    	//请求的查询数据
   
    Map map = RequestUtil.getMapByRequest(getRequest());
    LoginUserForm user=(LoginUserForm)getRequest().getSession().getAttribute("SES_LOGIN_USER"); 
  	OmOrgForm orgname=user.getOrg();
    if(page==null){
  		  page = new Page(15);
  	 }
    ExtUtils.initPageFromExtGridParam(getRequest(), page);
  	page=ywXzXkSpStateService.search(page,map);
  	
  	renderText(Struts2Utils.getJsonString(page, DateUtils.YYYY_MM_DD_HH_MM_SS));
  	
  	return null;
  }
    
    /**
     * 导出审批查询数据
     * @return
     * @throws IOException 
     */
    public String exportData() throws IOException{
    	Map map=RequestUtil.getMapByRequest(getRequest());
    	String contextpath=getRequest().getRealPath("");
		map.put("contextpath", contextpath);
    	String path= this.ywXzXkSpStateService.exportExcel(map);
		if(StringUtils.isNotBlank(path)){
			getResponse().getWriter().print(path);
		}
    	return null;
    }
    
    /**
     * 导出统计数据
     * @return
     * @throws IOException
     */
    public String  exportStateData() throws IOException{
    	Map map=RequestUtil.getMapByRequest(getRequest());
    	String contextpath=getRequest().getRealPath("");
		map.put("contextpath", contextpath);
    	String path= this.ywXzXkSpStateService.exportStateExcel(map);
		if(StringUtils.isNotBlank(path)){
			getResponse().getWriter().print(path);
		}
    	return null;
    }
   
    
    /**
     * 行政许可审批统计
     * @return
     */
    public String getResultState(){
    	return "resultState";
    }
    
    /**
     * 行政许可审批统计
     * @return
     */
    public String getInfos(){
    	Map map=RequestUtil.getMapByRequest(getRequest());
    	YwRqStateForm form=ywXzXkSpStateService.searchInfo(map);
    	this.getRequest().setAttribute("form",form);
    	return "resultInfo";
    }
    
    
    /**
     * 到查询首页
     * @return
     */
    public String queryList(){
    	return Constant.QUERYlIST;
    }
    
	@Override
	public String execute() throws Exception {
		return SUCCESS;
	}
    
	/**
	 * 取得HttpRequest的简化方法.
	 */
	private static HttpServletRequest getRequest() {
		return ServletActionContext.getRequest();
	}

	/**
	 * 取得HttpResponse的简化方法.
	 */
	private static HttpServletResponse getResponse() {
		return ServletActionContext.getResponse();
	}
	public Object getModel() {
		return null;
	}
	/**
	 * 直接输出文本.
	 * @see #render(String, String, String...)
	 */
	public static void renderText(final String text, final String... headers) {
		Struts2Utils.renderText(text, headers);
	}
}
